package com.tbh.ioc.container.applicationContext;

import com.tbh.ioc.bean.HelloWorld;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

@Import({HelloWorld.class})
@ImportResource(locations = "classpath:Beans.xml")
@ImportAutoConfiguration({HelloWorld.class})
public class AnnotationConfigApplicationContextMain {

    public static void main(String[] args) {
        // -获取注解配置的bean
        // 1.目标bean需要添加注解，并配置bean的value。例如： @Service("helloWorld")、@Component("helloWorld")、@Configuration("helloWorld")
        // 2.调用的类，需要导入Bean。例如： @Import({HelloWorld.class})，@ImportResource(locations = "classpath:Beans.xml")，@ImportAutoConfiguration({HelloWorld.class})
        ApplicationContext applicationContext1 = new AnnotationConfigApplicationContext(AnnotationConfigApplicationContextMain.class);
        HelloWorld helloWorld1 = (HelloWorld) applicationContext1.getBean("helloWorld");
        helloWorld1.setMessage("AnnotationConfigApplicationContext getBean");
        String message = helloWorld1.getMessage();
        System.out.println(message);
    }
}
